package com.heima.ThreadPool.ExecutorService3ways;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: Ethan Yankang
 * @Program: 面试必会代码
 * @Date: 2024-08-29 11:34
 **/
public class newSingleThreadPool {
    public static void main(String[] args) {
        ExecutorService es = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10; i++) {
            final int taskId=i;
                es.submit(()->{
                    System.out.println("线程 "+Thread.currentThread().threadId()+" is running,taskId="+taskId);
                });
        }
    }
}

/*原理任然是祖师爷7参数来的
*public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory) {
        return new AutoShutdownDelegatedExecutorService
            (new ThreadPoolExecutor(1, 1,
                                    0L, TimeUnit.MILLISECONDS,
                                    new LinkedBlockingQueue<Runnable>(),
                                    threadFactory));
    }
*/
